<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="test">
    </div>
    <script>
        //使用原生的post方式的时候要设置一个请求头 在open()方法和send()之间设置
        var test = document.getElementById("test");
        //1.创建ajax核心对象
        var xhr = new XMLHttpRequest();
        var url = "https://www.easy-mock.com/mock/5b3b16cdb35f9276a57e736a/11/post";
        //2.与服务器建立连接
        xhr.open("post", url);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        //3.发送请求
        xhr.send();
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4 && xhr.status == 200) {
                var txt = JSON.parse(xhr.responseText).data.content;
                console.log(txt);
                test.innerHTML = txt;
            } else {
                document.body.innerHTML = xhr.status;
            }
        }
    </script>
</body>

</html>